﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace TestAnimation
{
    class Ufo:ScreenObject
    {
        private int waitBeforeTurn;
        private int waitBeforeShoot;
        private double errorInCourse = .3d;

        public Ufo()
        {
            objectHeight = 800;
            objectWidth = 180;
            objectSize = objectHeight;
            waitBeforeTurn = Globals.ufoWaitTurn * Globals.FPS / 1000;
            waitBeforeShoot = Globals.ufoWaitShoot * Globals.FPS / 1000;

            int xPos;
            if (Helper.GetRnd(2) == 1) xPos = -objectSize;
            else xPos = Globals.maxX + objectSize;

            position = new Vector(xPos, Helper.GetRnd(Globals.maxY));
            ObjectOrientation = 0;

            CourseOrientation = xPos == -objectSize ? 0 : 180;

            Speed = 20;
            SetVelocity();
            points = new ArrayList(6);
            transformedPoints = new ArrayList(6);
            int h = objectHeight / 2;
            int w = objectWidth / 2;
            
            points.Add(new Point(-h, w));
            points.Add(new Point(-h*3/4, 0));
            points.Add(new Point(-h*2/3, -w));
            points.Add(new Point(h*2/3, -w));
            points.Add(new Point(h * 3 / 4, 0));
            points.Add(new Point(h, w));


        }
        public void Move(Vector shipPosition)
        {
            Move();     // base class
            
            if(--waitBeforeTurn<0)
            {
                waitBeforeTurn = Globals.ufoWaitTurn * Globals.FPS / 1000;
                errorInCourse *= -1;
                courseOrientation = (shipPosition-position).Angle() + errorInCourse;
                SetVelocity();
            }
        }
        public Bullet Shoot(Vector shipPosition)
        {
            if(--waitBeforeShoot<0)
            {
                waitBeforeShoot = Globals.ufoWaitShoot * Globals.FPS / 1000;

                Bullet bullet = new Bullet
                                    {
                                        position = position,
                                        velocity = (shipPosition - position).Normalize()*50,
                                        life = Globals.bulletMaxLife,
                                        bulletType = Bullet.BulletType.BAD
                                    };
                return bullet;
            }
            return null;
        }
    }
}
